package cn.rtplay.esp32camcar;

import android.content.Context;

import org.jetbrains.annotations.NotNull;

import cn.rtplay.esp32camcar.toolUtils.ConfUtil;

/**
 * The type Scan item.
 */
public class ScanItem {
    private String mCarNO;
    private String mCarModel;
    private String mSSID;
    private int mCarBrandId;
    private String mCarModelColor;

    /**
     * Instantiates a new Scan item.
     */
    public ScanItem() {
    }

    /**
     * Instantiates a new Scan item.
     *
     * @param context the context
     * @param data    the data
     * @param carNO   the car no
     * @param ssid  the wifi ssid
     */
    public ScanItem(Context context, @NotNull String data, @NotNull String carNO, @NotNull String ssid) {
        setRawData(context, data, carNO, ssid);
    }

    /**
     * Gets car no.
     *
     * @return the car no
     */
    public String getCarNO() {
        return mCarNO;
    }

    /**
     * Sets car no.
     *
     * @param mCarNO the m car no
     */
    public void setCarNO(String mCarNO) {
        this.mCarNO = mCarNO;
    }

    /**
     * Gets car model.
     *
     * @return the car model
     */
    public String getCarModel() {
        return mCarModel;
    }

    /**
     * Sets car model.
     *
     * @param mCarModel the m car model
     */
    public void setCarModel(String mCarModel) {
        this.mCarModel = mCarModel;
    }

    /**
     * Gets wifi ssid.
     *
     * @return the wifi ssid
     */
    public String getWifiSSID() {
        return mSSID;
    }

    /**
     * Sets bt addr.
     *
     * @param ssid the wifi ssid
     */
    public void setWifiSSID(String ssid) {
        this.mSSID = ssid;
    }

    /**
     * Gets car brand id.
     *
     * @return the car brand id
     */
    public int getCarBrandId() {
        return mCarBrandId;
    }

    /**
     * Sets car brand id.
     *
     * @param mCarBrandId the m car brand id
     */
    public void setCarBrandId(int mCarBrandId) {
        this.mCarBrandId = mCarBrandId;
    }

    /**
     * Gets car model color.
     *
     * @return the car model color
     */
    public String getCarModelColor() {
        return mCarModelColor;
    }

    /**
     * Sets car model color.
     *
     * @param mCarModelColor the m car model color
     */
    public void setCarModelColor(String mCarModelColor) {
        this.mCarModelColor = mCarModelColor;
    }

    /**
     * Sets raw data.
     *
     * @param context the context
     * @param data    the data
     * @param carNO   the car no
     * @param ssid  the wifi ssid
     */
    public void setRawData(Context context, @NotNull String data, @NotNull String carNO, @NotNull String ssid) {
        if (!carNO.isEmpty()) {
            mCarNO = carNO;
        } else {
            mCarNO = "xxxxxx";
        }
        if (!ssid.isEmpty()) {
            mSSID = ssid;
        } else {
            mSSID = "rtcar-xxxxxxx-xxxxxx";
        }
        if (data.length() == 7) {
            String carColor = ConfUtil.getInstance().findColorValue(data.substring(0, 3));
            if (carColor != null) {
                mCarModelColor = carColor;
            } else {
                mCarModelColor = "#000000";
            }
            String brand = ConfUtil.getInstance().findBrandName(data.substring(3, 6));
            if (brand != null) {
                int brandId = context.getResources().getIdentifier(brand, "raw", "cn.rtplay.esp32camcar");
                if (brandId != 0) {
                    mCarBrandId = brandId;
                } else {
                    mCarBrandId = context.getResources().getIdentifier("aodi", "raw", "cn.rtplay.esp32camcar");
                }
            } else {
                mCarBrandId = context.getResources().getIdentifier("aodi", "raw", "cn.rtplay.esp32camcar");
            }
            String model = ConfUtil.getInstance().findModelName(data.substring(3,6), data.substring(6));
            if (model != null) {
                mCarModel = model;
            } else {
                mCarModel = "";
            }
        }
    }

}
